/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.javanile.chesslang;

/**
 *
 * @author totalinnovation
 */
public class Stone {

    final static int
	BOARD_SIZE	= 64,
	BOARD_LENGTH	= 80;

    final static int
	a8= 0, b8= 1, c8= 2, d8= 3, e8= 4, f8= 5, g8= 6, h8= 7,
	a7= 8, b7= 9, c7=10, d7=11, e7=12, f7=13, g7=14, h7=15,
	a6=16, b6=17, c6=18, d6=19, e6=20, f6=21, g6=22, h6=23,
	a5=24, b5=25, c5=26, d5=27, e5=28, f5=29, g5=30, h5=31,
	a4=32, b4=33, c4=34, d4=35, e4=36, f4=37, g4=38, h4=39,
	a3=40, b3=41, c3=42, d3=43, e3=44, f3=45, g3=46, h3=47,
	a2=48, b2=49, c2=50, d2=51, e2=52, f2=53, g2=54, h2=55,
	a1=56, b1=57, c1=58, d1=59, e1=60, f1=61, g1=62, h1=63;

    final static int
	wp=+1, wn=+2, wb=+3, wr=+4, wq=+5, wk=+6,
	bp=-1, bn=-2, bb=-3, br=-4, bq=-5, bk=-6,
	_ = 0;

    final static int
	turn=64,
	wksc=67,
	wqsc=68,
	bksc=69,
	bqsc=70;

    final static int
	rrn=0,rrc=1,rrs=2,rrp=3;

    final static int
	white=1, black=-1, yes=1;

    final static int[] start = {
	/*a8*/br,/*b8*/bn,/*c8*/bb,/*d8*/bq,/*e8*/bk,/*f8*/bb,/*g8*/bn,/*h8*/br,
	/*a7*/bp,/*b7*/bp,/*c7*/bp,/*d7*/bp,/*e7*/bp,/*f7*/bp,/*g7*/bp,/*h7*/bp,
	/*a6*/_, /*b6*/_, /*c6*/_, /*d6*/_, /*e6*/_, /*f6*/_, /*g6*/_, /*h6*/_,
	/*a5*/_, /*b5*/_, /*c5*/_, /*d5*/_, /*e5*/_, /*f5*/_, /*g5*/_, /*h5*/_,
	/*a4*/_, /*b4*/_, /*c4*/_, /*d4*/_, /*e4*/_, /*f4*/_, /*g4*/_, /*h4*/_,
	/*a3*/_, /*b3*/_, /*c3*/_, /*d3*/_, /*e3*/_, /*f3*/_, /*g3*/_, /*h3*/_,
	/*a2*/wp,/*b2*/wp,/*c2*/wp,/*d2*/wp,/*e2*/wp,/*f2*/wp,/*g2*/wp,/*h2*/wp,
	/*a1*/wr,/*b1*/wn,/*c1*/wb,/*d1*/wq,/*e1*/wk,/*f1*/wb,/*g1*/wn,/*h1*/wr,
	/*turn*/white,
	/*number white piece*/16,
	/*number black piece*/16,
	/*white king  side castling*/yes,
	/*white queen side castling*/yes,
	/*black king  side castling*/yes,
	/*black queen side castling*/yes,
    };

    final static int[][] _nn = {
	/*a8*/{},			/*b8*/{},			/*c8*/{},		      /*d8*/{},			    /*e8*/{},			  /*f8*/{},			/*g8*/{},		      /*h8*/{},
	/*a7*/{a8},			/*b7*/{b8},			/*c7*/{c8},		      /*d7*/{d8},		    /*e7*/{e8},			  /*f7*/{f8},			/*g7*/{g8},		      /*h7*/{h8},
	/*a6*/{a7,a8},			/*b6*/{b7,b8},			/*c6*/{c7,c8},		      /*d6*/{d7,d8},		    /*e6*/{e7,e8},		  /*f6*/{f7,f8},		/*g6*/{g7,g8},		      /*h6*/{h7,h8},
	/*a5*/{a6,a7,a8},		/*b5*/{b6,b7,b8},		/*c5*/{c6,c7,c8},	      /*d5*/{d6,d7,d8},		    /*e5*/{e6,e7,e8},		  /*f5*/{f6,f7,f8},		/*g5*/{g6,g7,g8},	      /*h5*/{h6,h7,h8},
	/*a4*/{a5,a6,a7,a8},		/*b4*/{b5,b6,b7,b8},		/*c4*/{c5,c6,c7,c8},	      /*d4*/{d5,d6,d7,d8},	    /*e4*/{e5,e6,e7,e8},	  /*f4*/{f5,f6,f7,f8},		/*g4*/{g5,g6,g7,g8},	      /*h4*/{h5,h6,h7,h8},
	/*a3*/{a4,a5,a6,a7,a8},		/*b3*/{b4,b5,b6,b7,b8},		/*c3*/{c4,c5,c6,c7,c8},	      /*d3*/{d4,d5,d6,d7,d8},	    /*e3*/{e4,e5,e6,e7,e8},	  /*f3*/{f4,f5,f6,f7,f8},	/*g3*/{g4,g5,g6,g7,g8},	      /*h3*/{h4,h5,h6,h7,h8},
	/*a2*/{a3,a4,a5,a6,a7,a8},	/*b2*/{b3,b4,b5,b6,b7,b8},	/*c2*/{c3,c4,c5,c6,c7,c8},    /*d2*/{d3,d4,d5,d6,d7,d8},    /*e2*/{e3,e4,e5,e6,e7,e8},    /*f2*/{f3,f4,f5,f6,f7,f8},    /*g2*/{g3,g4,g5,g6,g7,g8},    /*h2*/{h3,h4,h5,h6,h7,h8},
	/*a1*/{a2,a3,a4,a5,a6,a7,a8},	/*b1*/{b2,b3,b4,b5,b6,b7,b8},	/*c1*/{c2,c3,c4,c5,c6,c7,c8}, /*d1*/{d2,d3,d4,d5,d6,d7,d8}, /*e1*/{e2,e3,e4,e5,e6,e7,e8}, /*f1*/{f2,f3,f4,f5,f6,f7,f8}, /*g1*/{g2,g3,g4,g5,g6,g7,g8}, /*h1*/{h2,h3,h4,h5,h6,h7,h8},
    };

    final static int[][] _ss = {
	/*a8*/{a7,a6,a5,a4,a3,a2,a1},/*b8*/{b7,b6,b5,b4,b3,b2,b1}, /*c8*/{}, /*d8*/{}, /*e8*/{}, /*f8*/{}, /*g8*/{}, /*h8*/{},
	/*a7*/{a6,a5,a4,a3,a2,a1},   /*b7*/{b6,b5,b4,b3,b2,b1},	   /*c7*/{}, /*d7*/{}, /*e7*/{}, /*f7*/{}, /*g7*/{}, /*h7*/{},
	/*a6*/{a5,a4,a3,a2,a1},	     /*b6*/{b5,b4,b3,b2,b1},	   /*c6*/{}, /*d6*/{}, /*e6*/{}, /*f6*/{}, /*g6*/{}, /*h6*/{},
	/*a5*/{a4,a3,a2,a1},	     /*b5*/{b4,b3,b2,b1},	   /*c5*/{}, /*d5*/{}, /*e5*/{}, /*f5*/{}, /*g5*/{}, /*h5*/{},
	/*a4*/{a3,a2,a1},	     /*b4*/{b3,b2,b1},		   /*c4*/{}, /*d4*/{}, /*e4*/{}, /*f4*/{}, /*g4*/{}, /*h4*/{},
	/*a3*/{a2,a1},		     /*b3*/{b2,b1},		   /*c3*/{}, /*d3*/{}, /*e3*/{}, /*f3*/{}, /*g3*/{}, /*h3*/{},
	/*a2*/{a1},		     /*b2*/{b1},		   /*c2*/{}, /*d2*/{}, /*e2*/{}, /*f2*/{}, /*g2*/{}, /*h2*/{},
	/*a1*/{},		     /*b1*/{},			   /*c1*/{}, /*d1*/{}, /*e1*/{}, /*f1*/{}, /*g1*/{}, /*h1*/{},
    };

    final static int[][] _ee = {
	/*a8*/{b8,c8,d8,e8,f8,g8,h8}, /*b8*/{c8,d8,e8,f8,g8,h8}, /*c8*/{d8,e8,f8,g8,h8}, /*d8*/{e8,f8,g8,h8}, /*e8*/{f8,g8,h8}, /*f8*/{g8,h8}, /*g8*/{h8}, /*h8*/{},
	/*a7*/{b7,c7,d7,e7,f7,g7,h7}, /*b7*/{c7,d7,e7,f7,g7,h7}, /*c7*/{d7,e7,f7,g7,h7}, /*d7*/{e7,f7,g7,h7}, /*e7*/{f7,g7,h7}, /*f7*/{g7,h7}, /*g7*/{h7}, /*h7*/{},
	/*a6*/{b6,c6,d6,e6,f6,g6,h6}, /*b6*/{c6,d6,e6,f6,g6,h6}, /*c6*/{d6,e6,f6,g6,h6}, /*d6*/{e6,f6,g6,h6}, /*e6*/{f6,g6,h6}, /*f6*/{g6,h6}, /*g6*/{h6}, /*h6*/{},
	/*a5*/{b5,c5,d5,e5,f5,g5,h5}, /*b5*/{c5,d5,e5,f5,g5,h5}, /*c5*/{d5,e5,f5,g5,h5}, /*d5*/{e5,f5,g5,h5}, /*e5*/{f5,g5,h5}, /*f5*/{g5,h5}, /*g5*/{h5}, /*h5*/{},
	/*a4*/{b4,c4,d4,e4,f4,g4,h4}, /*b4*/{c4,d4,e4,f4,g4,h4}, /*c4*/{d4,e4,f4,g4,h4}, /*d4*/{e4,f4,g4,h4}, /*e4*/{f4,g4,h4}, /*f4*/{g4,h4}, /*g4*/{h4}, /*h4*/{},
	/*a3*/{b3,c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, /*h5*/{g8,f8,e8,d8,c8,b8,a8},
	/*a4*/{}, /*b4*/{a4}, /*c4*/{b4,a4}, /*d4*/{c4,b4,a4}, /*e4*/{d8,c8,b8,a8}, /*f4*/{e4,d4,c8,b8,a8}, /*g4*/{f8,e8,d8,c8,b8,a8}, /*h4*/{g8,f8,e8,d8,c8,b8,a8},
	/*a3*/{}, /*b3*/{a3}, /*c3*/{b3,a3}, /*d3*/{c3,b3,a3}, /*e3*/{d8,c8,b8,a8}, /*f3*/{e3,d3,c8,b8,a8}, /*g3*/{f8,e8,d8,c8,b8,a8}, /*h3*/{g8,f8,e8,d8,c8,b8,a8},
	/*a2*/{}, /*b2*/{a2}, /*c2*/{b2,a2}, /*d2*/{c2,b2,a2}, /*e2*/{d8,c8,b8,a8}, /*f2*/{e2,d2,c8,b8,a8}, /*g2*/{f8,e8,d8,c8,b8,a8}, /*h2*/{g8,f8,e8,d8,c8,b8,a8},
	/*a1*/{}, /*b1*/{a1}, /*c1*/{b1,a1}, /*d1*/{c1,b1,a1}, /*e1*/{d8,c8,b8,a8}, /*f1*/{e1,d1,c8,b8,a8}, /*g1*/{f8,e8,d8,c8,b8,a8}, /*h1*/{g1,f1,e1,d1,c1,b1,a1},
    };

    final static int[][] _ne = {
	/*a8*/{},		      /*b8*/{},			 /*c8*/{},		 /*d8*/{},	      /*e8*/{},		/*f8*/{},      /*g8*/{},   /*h8*/{},
	/*a7*/{b8},		      /*b7*/{c8},		 /*c7*/{d8},		 /*d7*/{e8},	      /*e7*/{f8},	/*f7*/{g8},    /*g7*/{h8}, /*h7*/{},
	/*a6*/{b7,c8},		      /*b6*/{c7,d8},		 /*c6*/{d7,e8},		 /*d6*/{e7,f8},	      /*e6*/{f7,g8},	/*f6*/{g7,h8}, /*g6*/{h7}, /*h6*/{},
	/*a5*/{b6,c7,d8},	      /*b5*/{c6,d7,e8},		 /*c5*/{d6,e7,f8},	 /*d5*/{e6,f7,g8},    /*e5*/{f6,g7,h8}, /*f5*/{g6,h7}, /*g5*/{h6}, /*h5*/{},
	/*a4*/{b5,c6,d7,e8},	      /*b4*/{c5,d6,e7,f8},	 /*c4*/{d5,e6,f7,g8},	 /*d4*/{e5,f6,g7,h8}, /*e4*/{f5,g6,h7}, /*f4*/{g5,h6}, /*g4*/{h5}, /*h4*/{},
	/*a3*/{b4,c5,d6,e7,f8},	      /*b3*/{c4,d5,e6,f7,g8},	 /*c3*/{d4,e5,f6,g7,h8}, /*d3*/{e4,f5,g6,h7}, /*e3*/{f4,g5,h6}, /*f3*/{g4,h5}, /*g3*/{h4}, /*h3*/{},
	/*a2*/{b3,c4,d5,e6,f7,g8},    /*b2*/{c3,d4,e5,f6,g7,h8}, /*c2*/{d3,e4,f5,g6,h7}, /*d2*/{e3,f4,g5,h6}, /*e2*/{f3,g4,h5}, /*f2*/{g3,h4}, /*g2*/{h3}, /*h2*/{},
	/*a1*/{b2,c3,d4,e5,f6,g7,h8}, /*b1*/{c2,d3,e4,f5,g6,h7}, /*c1*/{d2,e3,f4,g5,h6}, /*d1*/{e2,f3,g4,h5}, /*e1*/{f2,g3,h4}, /*f1*/{g2,h3}, /*g1*/{h2}, /*h1*/{},
    };

    final static int[][] _nw = {
	/*a8*/{}, /*b8*/{},   /*c8*/{},	     /*d8*/{},	       /*e8*/{},	    /*f8*/{},		    /*g8*/{},		       /*h8*/{},
	/*a7*/{}, /*b7*/{a8}, /*c7*/{b8},    /*d7*/{c8},       /*e7*/{d8},	    /*f7*/{e8},		    /*g7*/{f8},		       /*h7*/{g8},
	/*a6*/{}, /*b6*/{a7}, /*c6*/{b7,a8}, /*d6*/{c7,b8},    /*e6*/{d7,c8},	    /*f6*/{e7,d8},	    /*g6*/{f7,e8},	       /*h6*/{g7,f8},
	/*a5*/{}, /*b5*/{a6}, /*c5*/{b6,a7}, /*d5*/{c6,b7,a8}, /*e5*/{d6,c7,b8},    /*f5*/{e6,d7,c8},	    /*g5*/{f6,e7,d8},	       /*h5*/{g6,f7,e8},
	/*a4*/{}, /*b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,d2,e1},		/*b5*/{c4,d3,e2,f1},	   /*c5*/{d4,e3,f2,g1},	   /*d5*/{e4,f3,g2,h1}, /*e5*/{f4,g3,h2}, /*f5*/{g4,h3}, /*g5*/{h4}, /*h5*/{},
	/*a4*/{b3,c2,d1},		/*b4*/{c3,d2,e1},	   /*c4*/{d3,e2,f1},	   /*d4*/{e3,f2,g1},	/*e4*/{f3,g2,h1}, /*f4*/{g3,h2}, /*g4*/{h3}, /*h4*/{},
	/*a3*/{b2,c1},			/*b3*/{c2,d1},		   /*c3*/{d2,e1},	   /*d3*/{e2,f1},	/*e3*/{f2,g1},	  /*f3*/{g2,h1}, /*g3*/{h2}, /*h3*/{},
	/*a2*/{b1},			/*b2*/{c1},		   /*c2*/{d1},		   /*d2*/{e1},		/*e2*/{f1},	  /*f2*/{g1},	 /*g2*/{h1}, /*h2*/{},
	/*a1*/{},			/*b1*/{},		   /*c1*/{},		   /*d1*/{},		/*e1*/{},	  /*f1*/{},	 /*g1*/{}, /*h1*/{},
    };

    final static int[][] _sw = {
	/*a8*/{},			/*b8*/{}, /*c8*/{}, /*d8*/{}, /*e8*/{}, /*f8*/{}, /*g8*/{}, /*h8*/{},
	/*a7*/{a8},			/*b7*/{}, /*c7*/{}, /*d7*/{}, /*e7*/{}, /*f7*/{}, /*g7*/{}, /*h7*/{},
	/*a6*/{a7,a8},			/*b6*/{}, /*c6*/{}, /*d6*/{}, /*e6*/{}, /*f6*/{}, /*g6*/{}, /*h6*/{},
	/*a5*/{a6,a7,a8},		/*b5*/{}, /*c5*/{}, /*d5*/{}, /*e5*/{}, /*f5*/{}, /*g5*/{}, /*h5*/{},
	/*a4*/{a5,a6,a7,a8},		/*b4*/{}, /*c4*/{}, /*d4*/{}, /*e4*/{}, /*f4*/{}, /*g4*/{}, /*h4*/{},
	/*a3*/{a4,a5,a6,a7,a8},		/*b3*/{}, /*c3*/{}, /*d3*/{}, /*e3*/{}, /*f3*/{}, /*g3*/{}, /*h3*/{},
	/*a2*/{a3,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/{},   /*g8*/{},   /*h8*/{},
	/*a7*/{a8}, /*b7*/{b8}, /*c7*/{c8}, /*d7*/{d8}, /*e7*/{e8}, /*f7*/{f8}, /*g7*/{g8}, /*h7*/{h8},
	/*a6*/{a7}, /*b6*/{b7}, /*c6*/{c7}, /*d6*/{d7}, /*e6*/{e7}, /*f6*/{f7}, /*g6*/{g7}, /*h6*/{h7},
	/*a5*/{a6}, /*b5*/{b6}, /*c5*/{c6}, /*d5*/{d6}, /*e5*/{e6}, /*f5*/{f6}, /*g5*/{g6}, /*h5*/{h6},
	/*a4*/{a5}, /*b4*/{b5}, /*c4*/{c5}, /*d4*/{d5}, /*e4*/{e5}, /*f4*/{f5}, /*g4*/{g5}, /*h4*/{h5},
	/*a3*/{a4}, /*b3*/{b4}, /*c3*/{c4}, /*d3*/{d4}, /*e3*/{e4}, /*f3*/{f4}, /*g3*/{g4}, /*h3*/{h4},
	/*a2*/{},   /*b2*/{},   /*c2*/{},   /*d2*/{},   /*e2*/{},   /*f2*/{},   /*g2*/{},   /*h2*/{},
	/*a1*/{},   /*b1*/{},   /*c1*/{},   /*d1*/{},   /*e1*/{},   /*f1*/{},   /*g1*/{},   /*h1*/{},
    };

    final static int[][] _wpc = {
	/*a8*/{},   /*b8*/{},	   /*c8*/{},	  /*d8*/{},	 /*e8*/{},	/*f8*/{},      /*g8*/{},      /*h8*/{},
	/*a7*/{b8}, /*b7*/{a8,c8}, /*c7*/{b8,d8}, /*d7*/{c8,e8}, /*e7*/{d8,f8}, /*f7*/{e8,g8}, /*g7*/{f8,h8}, /*h7*/{g8},
	/*a6*/{b7}, /*b6*/{a7,c7}, /*c6*/{b7,d7}, /*d6*/{c7,e7}, /*e6*/{d7,f7}, /*f6*/{e7,g7}, /*g6*/{f7,h7}, /*h6*/{g7},
	/*a5*/{b6}, /*b5*/{a6,c6}, /*c5*/{b6,d6}, /*d5*/{c6,e6}, /*e5*/{d6,f6}, /*f5*/{e6,g6}, /*g5*/{f6,h6}, /*h5*/{g6},
	/*a4*/{b5}, /*b4*/{a5,c5}, /*c4*/{b5,d5}, /*d4*/{c5,e5}, /*e4*/{d5,f5}, /*f4*/{e5,g5}, /*g4*/{f5,h5}, /*h4*/{g5},
	/*a3*/{b4}, /*b3*/{a4,c4}, /*c3*/{b4,d4}, /*d3*/{c4,e4}, /*e3*/{d4,f4}, /*f3*/{e4,g4}, /*g3*/{f4,h4}, /*h3*/{g4},
	/*a2*/{b3}, /*b2*/{a3,c3}, /*c2*/{b3,d3}, /*d2*/{c3,e3}, /*e2*/{d3,f3}, /*f2*/{e3,g3}, /*g2*/{f3,h3}, /*h2*/{g3},
	/*a1*/{},   /*b1*/{},	   /*c1*/{},	  /*d1*/{},	 /*e1*/{},	/*f1*/{},      /*g1*/{},      /*h1*/{},
    };

    final static int[][] _wpd = {
	/*a8*/{},	/*b8*/{},	/*c8*/{},	/*d8*/{}, /*e8*/{}, /*f8*/{}, /*g8*/{}, /*h8*/{},
	/*a7*/{},	/*b7*/{},	/*c7*/{},	/*d7*/{}, /*e7*/{}, /*f7*/{}, /*g7*/{}, /*h7*/{},
	/*a6*/{},	/*b6*/{},	/*c6*/{},	/*d6*/{}, /*e6*/{}, /*f6*/{}, /*g6*/{}, /*h6*/{},
	/*a5*/{},	/*b5*/{},	/*c5*/{},	/*d5*/{}, /*e5*/{}, /*f5*/{}, /*g5*/{}, /*h5*/{},
	/*a4*/{},	/*b4*/{},	/*c4*/{},	/*d4*/{}, /*e4*/{}, /*f4*/{}, /*g4*/{}, /*h4*/{},
	/*a3*/{},	/*b3*/{},	/*c3*/{},	/*d3*/{}, /*e3*/{}, /*f3*/{}, /*g3*/{}, /*h3*/{},
	/*a2*/{a3,a4},	/*b2*/{b3,b4},	/*c2*/{c3,c4},	/*d2*/{d3,d4}, /*e2*/{e3,e4}, /*f2*/{f3,f4}, /*g2*/{g3,g4}, /*h2*/{h3,h4},
	/*a1*/{},	/*b1*/{},	/*c1*/{},	/*d1*/{}, /*e1*/{}, /*f1*/{}, /*g1*/{}, /*h1*/{},
    };

    final static int[][] _wpe = {
	/*a8*/{},   /*b8*/{},	   /*c8*/{},	  /*d8*/{},	 /*e8*/{},	/*f8*/{},      /*g8*/{},      /*h8*/{},
	/*a7*/{},   /*b7*/{},	   /*c7*/{},	  /*d7*/{},	 /*e7*/{},	/*f7*/{},      /*g7*/{},      /*h7*/{},
	/*a6*/{},   /*b6*/{},	   /*c6*/{},	  /*d6*/{},	 /*e6*/{},	/*f6*/{},      /*g6*/{},      /*h6*/{},
	/*a5*/{b6}, /*b5*/{a6,c6}, /*c5*/{b6,d6}, /*d5*/{c6,e6}, /*e5*/{d6,f6}, /*f5*/{e6,g6}, /*g5*/{f6,h6}, /*h5*/{g6},
	/*a4*/{},   /*b4*/{},	   /*c4*/{},	  /*d4*/{},	 /*e4*/{},	/*f4*/{},      /*g4*/{},      /*h4*/{},
	/*a3*/{},   /*b3*/{},	   /*c3*/{},	  /*d3*/{},	 /*e3*/{},	/*f3*/{},      /*g3*/{},      /*h3*/{},
	/*a2*/{},   /*b2*/{},	   /*c2*/{},	  /*d2*/{},	 /*e2*/{},	/*f2*/{},      /*g2*/{},      /*h2*/{},
	/*a1*/{},   /*b1*/{},	   /*c1*/{},	  /*d1*/{},	 /*e1*/{},	/*f1*/{},      /*g1*/{},      /*h1*/{},
    };

    final static int[][] _bpn = {
	/*a8*/{},   /*b8*/{}, /*c8*/{}, /*d8*/{}, /*e8*/{}, /*f8*/{}, /*g8*/{}, /*h8*/{},
	/*a7*/{},   /*b7*/{}, /*c7*/{}, /*d7*/{}, /*e7*/{}, /*f7*/{}, /*g7*/{}, /*h7*/{},
	/*a6*/{a5}, /*b6*/{b5}, /*c6*/{c5}, /*d6*/{d5}, /*e6*/{e5}, /*f6*/{f5}, /*g6*/{g5}, /*h6*/{h5},
	/*a5*/{a4}, /*b5*/{b4}, /*c5*/{c4}, /*d5*/{d4}, /*e5*/{e4}, /*f5*/{f4}, /*g5*/{g4}, /*h5*/{h4},
	/*a4*/{a3}, /*b4*/{b3}, /*c4*/{c3}, /*d4*/{d3}, /*e4*/{e3}, /*f4*/{f3}, /*g4*/{g3}, /*h4*/{h3},
	/*a3*/{a2}, /*b3*/{b2}, /*c3*/{c2}, /*d3*/{d2}, /*e3*/{e2}, /*f3*/{f2}, /*g3*/{g2}, /*h3*/{h2},
	/*a2*/{a1}, /*b2*/{b1}, /*c2*/{c1}, /*d2*/{d1}, /*e2*/{e1}, /*f2*/{f1}, /*g2*/{g1}, /*h2*/{h1},
	/*a1*/{},   /*b1*/{}, /*c1*/{}, /*d1*/{}, /*e1*/{}, /*f1*/{}, /*g1*/{}, /*h1*/{},
    };

    final static int[][] _bpc = {
	/*a8*/{},   /*b8*/{},	   /*c8*/{},	  /*d8*/{},	 /*e8*/{},	/*f8*/{},      /*g8*/{},      /*h8*/{},
	/*a7*/{b6}, /*b7*/{a6,c6}, /*c7*/{b6,d6}, /*d7*/{c6,e6}, /*e7*/{d6,f6}, /*f7*/{e6,g6}, /*g7*/{f6,h6}, /*h7*/{g6},
	/*a6*/{b5}, /*b6*/{a5,c5}, /*c6*/{b5,d5}, /*d6*/{c5,e5}, /*e6*/{d5,f5}, /*f6*/{e5,g5}, /*g6*/{f5,h5}, /*h6*/{g5},
	/*a5*/{b4}, /*b5*/{a4,c4}, /*c5*/{b4,d4}, /*d5*/{c4,e4}, /*e5*/{d4,f4}, /*f5*/{e4,g4}, /*g5*/{f4,h4}, /*h5*/{g4},
	/*a4*/{b3}, /*b4*/{a3,c3}, /*c4*/{b3,d3}, /*d4*/{c3,e3}, /*e4*/{d3,f3}, /*f4*/{e3,g3}, /*g4*/{f3,h3}, /*h4*/{g3},
	/*a3*/{b2}, /*b3*/{a2,c2}, /*c3*/{b2,d2}, /*d3*/{c2,e2}, /*e3*/{d2,f2}, /*f3*/{e2,g2}, /*g3*/{f2,h2}, /*h3*/{g2},
	/*a2*/{b1}, /*b2*/{a1,c1}, /*c2*/{b1,d1}, /*d2*/{c1,e1}, /*e2*/{d1,f1}, /*f2*/{e1,g1}, /*g2*/{f1,h1}, /*h2*/{g1},
	/*a1*/{},   /*b1*/{},	   /*c1*/{},	  /*d1*/{},	 /*e1*/{},	/*f1*/{},      /*g1*/{},      /*h1*/{},
    };

    final static int[][] _bpd = {
	/*a8*/{},	/*b8*/{}, /*c8*/{}, /*d8*/{}, /*e8*/{}, /*f8*/{}, /*g8*/{}, /*h8*/{},
	/*a7*/{a6,a5},	/*b7*/{b6,b5}, /*c7*/{c6,c5}, /*d7*/{d6,d5}, /*e7*/{e6,e5}, /*f7*/{f6,f5}, /*g7*/{g6,g5}, /*h7*/{h6,h5},
	/*a6*/{},	/*b6*/{}, /*c6*/{}, /*d6*/{}, /*e6*/{}, /*f6*/{}, /*g6*/{}, /*h6*/{},
	/*a5*/{},	/*b5*/{}, /*c5*/{}, /*d5*/{}, /*e5*/{}, /*f5*/{}, /*g5*/{}, /*h5*/{},
	/*a4*/{},	/*b4*/{}, /*c4*/{}, /*d4*/{}, /*e4*/{}, /*f4*/{}, /*g4*/{}, /*h4*/{},
	/*a3*/{},	/*b3*/{}, /*c3*/{}, /*d3*/{}, /*e3*/{}, /*f3*/{}, /*g3*/{}, /*h3*/{},
	/*a2*/{},	/*b2*/{}, /*c2*/{}, /*d2*/{}, /*e2*/{}, /*f2*/{}, /*g2*/{}, /*h2*/{},
	/*a1*/{},	/*b1*/{}, /*c1*/{}, /*d1*/{}, /*e1*/{}, /*f1*/{}, /*g1*/{}, /*h1*/{},
    };

    final static int[][] _bpe = {
	/*a8*/{},   /*b8*/{},	   /*c8*/{},	  /*d8*/{},	 /*e8*/{},	/*f8*/{},      /*g8*/{},      /*h8*/{},
	/*a7*/{b6}, /*b7*/{a6,c6}, /*c7*/{b6,d6}, /*d7*/{c6,e6}, /*e7*/{d6,f6}, /*f7*/{e6,g6}, /*g7*/{f6,h6}, /*h7*/{g6},
	/*a6*/{b5}, /*b6*/{a5,c5}, /*c6*/{b5,d5}, /*d6*/{c5,e5}, /*e6*/{d5,f5}, /*f6*/{e5,g5}, /*g6*/{f5,h5}, /*h6*/{g5},
	/*a5*/{b4}, /*b5*/{a4,c4}, /*c5*/{b4,d4}, /*d5*/{c4,e4}, /*e5*/{d4,f4}, /*f5*/{e4,g4}, /*g5*/{f4,h4}, /*h5*/{g4},
	/*a4*/{b3}, /*b4*/{a3,c3}, /*c4*/{b3,d3}, /*d4*/{c3,e3}, /*e4*/{d3,f3}, /*f4*/{e3,g3}, /*g4*/{f3,h3}, /*h4*/{g3},
	/*a3*/{b2}, /*b3*/{a2,c2}, /*c3*/{b2,d2}, /*d3*/{c2,e2}, /*e3*/{d2,f2}, /*f3*/{e2,g2}, /*g3*/{f2,h2}, /*h3*/{g2},
	/*a2*/{b1}, /*b2*/{a1,c1}, /*c2*/{b1,d1}, /*d2*/{c1,e1}, /*e2*/{d1,f1}, /*f2*/{e1,g1}, /*g2*/{f1,h1}, /*h2*/{g1},
	/*a1*/{},   /*b1*/{},	   /*c1*/{},	  /*d1*/{},	 /*e1*/{},	/*f1*/{},      /*g1*/{},      /*h1*/{},
    };

    final static int[][] _kn = {
	/*a8*/{c7,b6},	     /*b8*/{a6,c6,d7},		/*c8*/{a7,b6,d6,e7},		 /*d8*/{b7,c6,e6,f7},		  /*e8*/{c7,d6,f6,g7},		   /*f8*/{d7,e6,g6,h7},		    /*g8*/{e7,f6,h6},	       /*h8*/{f7,g6},
	/*a7*/{c8,c6,b5},    /*b7*/{a5,c5,d6,d8},	/*c7*/{a6,a8,b5,d5,e6,e8},	 /*d7*/{b8,b6,c5,e5,f8,f6},	  /*e7*/{c8,c6,d5,f5,g8,g6},	   /*f7*/{d8,d6,e5,g5,h6,h8},	    /*g7*/{e8,e6,f5,h5},       /*h7*/{f8,f6,g5},
	/*a6*/{b8,c7,c5,b4}, /*b6*/{a4,a8,c4,c8,d5,d7}, /*c6*/{a5,a7,b4,b8,d4,d8,e5,e7}, /*d6*/{b5,b7,c4,c8,e4,e8,f5,f7}, /*e6*/{c5,c7,d4,d8,f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f3,g2},		   /*f1*/{d2,e3,g3,h2},		    /*g1*/{e2,f3,h3},	       /*h1*/{f2,g3}
    };

    final static int
	nn =0, ne =1, ee =2,se=3,ss=4,sw=5,ww=6,nw=7,
	wpn=8, wpc=9, wpd=10,wpe=11,
	bpn=12,bpc=13,bpd=14,bpe=15,
	kn =16,kk =17;

    final static int
	s=0,sc=1,c=2,ep=3,wlc=4,wrc=5,blc=6,brc=7,hc=8;

    final static int[][][] map = { _nn, _ne, _ee, _se, _ss, _sw, _ww, _nw,
				    _wpn,_wpc,_wpd,_wpe,_bpn,_bpc,_bpd,_bpe,
				    _kn, _kk
				  };

    final static int[]	    kid = {  sc,  sc,  sc,  sc,  sc,  sc,  sc,  sc,
				     s,   c,   s,   ep,  s,   c,   s,   ep,
				     hc,  hc
				  };

    final static int[]	    wps	= {wpn,wpc,wpd,wpe};
    final static int[]	    bps = {bpn,bpc,bpd,bpe};
    final static int[]	    qs  = {nn,ss,ww,ee,ne,nw,se,sw};
    final static int[]	    ns  = {kn};
    final static int[]	    bs  = {ne,nw,se,sw};
    final static int[]	    rs  = {nn,ss,ww,ee};
    final static int[]	    wks = {kk};
    final static int[]	    bks = {kk};
    
    final static int[][]   dir = {
	bks,
	qs,
	rs,
	bs,
	ns,
	bps,
	null,
	wps,
	ns,
	bs,
	rs,
	qs,
	wks
    };

    final static int from   = 0;
    final static int to	    = 1;

    final static int[] val = {
	/*pawn*/    100,
	/*knigth*/  290,
	/*bishop*/  310,
	/*rook*/    500,
	/*queen*/   900,
	/*king*/  10000
    };

    final static int[] boardval = {
	/*a8*/10, /*b8*/10, /*c8*/10, /*d8*/10, /*e8*/10, /*f8*/10, /*g8*/10, /*h8*/10,
	/*a7*/10, /*b7*/10, /*c7*/10, /*d7*/10, /*e7*/10, /*f7*/10, /*g7*/10, /*h7*/10,
	/*a6*/10, /*b6*/10, /*c6*/20, /*d6*/20, /*e6*/20, /*f6*/20, /*g6*/10, /*h6*/10,
	/*a5*/10, /*b5*/10, /*c5*/20, /*d5*/50, /*e5*/60, /*f5*/20, /*g5*/10, /*h5*/10,
	/*a4*/10, /*b4*/10, /*c4*/20, /*d4*/50, /*e4*/60, /*f4*/20, /*g4*/10, /*h4*/10,
	/*a3*/10, /*b3*/10, /*c3*/20, /*d3*/20, /*e3*/20, /*f3*/20, /*g3*/10, /*h3*/10,
	/*a2*/10, /*b2*/10, /*c2*/10, /*d2*/10, /*e2*/10, /*f2*/10, /*g2*/10, /*h2*/10,
	/*a1*/10, /*b1*/10, /*c1*/10, /*d1*/10, /*e1*/10, /*f1*/10, /*g1*/10, /*h1*/10
    };
} 

/*a8*/ /*b8*/ /*c8*/ /*d8*/ /*e8*/ /*f8*/ /*g8*/ /*h8*/
/*a7*/ /*b7*/ /*c7*/ /*d7*/ /*e7*/ /*f7*/ /*g7*/ /*h7*/
/*a6*/ /*b6*/ /*c6*/ /*d6*/ /*e6*/ /*f6*/ /*g6*/ /*h6*/
/*a5*/ /*b5*/ /*c5*/ /*d5*/ /*e5*/ /*f5*/ /*g5*/ /*h5*/
/*a4*/ /*b4*/ /*c4*/ /*d4*/ /*e4*/ /*f4*/ /*g4*/ /*h4*/
/*a3*/ /*b3*/ /*c3*/ /*d3*/ /*e3*/ /*f3*/ /*g3*/ /*h3*/
/*a2*/ /*b2*/ /*c2*/ /*d2*/ /*e2*/ /*f2*/ /*g2*/ /*h2*/
/*a1*/ /*b1*/ /*c1*/ /*d1*/ /*e1*/ /*f1*/ /*g1*/ /*h1*/
